Definition: POSITIONPRICE is a function in ProBuilder language that calculates the average price of all currently open positions. This function is particularly useful for traders who need to track the average entry price of multiple trades to manage their positions effectively.
PositionPrice
You can also access the average position price from previous periods by using an index offset. For example, PositionPrice[1] retrieves the average position price from the previous candle.
Consider a scenario where you want to calculate the floating profit of all open positions and implement a simple trading strategy that averages down based on specific conditions:
// Calculate floating profit
floatingprofit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
// Define MACD indicator
myMACD = MACD[12,26,9](close)
// Entry condition
long = myMACD crosses over 0
IF NOT LongOnMarket AND long THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Averaging down condition
IF TRADEINDEX(1) > 5 AND TRADEPRICE(1) - Close > 20 AND LongOnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Exit condition
IF COUNTOFPOSITION >= 2 AND Close > POSITIONPRICE THEN
SELL AT MARKET
ENDIF
// Set a target profit
SET TARGET PROFIT 20
floatingprofit variable calculates the current unrealized profit or loss of all open positions.This example demonstrates how to use POSITIONPRICE in a trading strategy to manage entries, averaging down, and exits based on the average price of open positions.